<?php

namespace app\api\model;

use think\Model;

class CourseCommentTag extends Model
{
    protected $autoWriteTimestamp = false;
    /**
     * 获取课程标签
     */
    public static function getByCourseId($courseCommentIds)
    {
        $tagId = self::whereIn('course_comment_id', $courseCommentIds)->column('tag_id');
        return $tagId ? array_values(array_unique($tagId)) : [];
    }

    /**
     * 添加标签
     */
    public static function add($courseCommentId, $tag)
    {
        $tags = explode(',', $tag);
        $data = [];
        foreach ($tags as $val) {
            $data[] = [
                'course_comment_id' => $courseCommentId,
                'tag_id' => $val
            ];
        }
        return self::insertAll($data);
    }
}
